package com.centit.suixuan.puremvc.model
{
	import com.centit.suixuan.puremvc.AppFacade;
	
	import mx.controls.Tree;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	import spark.components.Group;
	import spark.components.Panel;

	public class MenuProxy extends Proxy implements IProxy
	{
		public function MenuProxy(proxyName : String = null, data : Object = null)
		{
			super(proxyName, data);
				
		}
		
		public static const NAME:String = "MenuProxy";
		
		public function chanPanel() : void {
			var treeMenu : Tree = data.treeMenu as Tree;
			var mainApplication : MainApplication = data.mainApplication as MainApplication;
			
			var xml:XML=treeMenu.selectedItem as XML;
			//var text:String=xml.text;
			//trace(xml.@id);
			
			mainApplication.palRight.removeAllElements();
			
			var id : String = xml.@id;
			switch(id){
				case "image" : 
					var imgPanel : Group = new ImagePanel();
					
					mainApplication.palRight.addElement(imgPanel);
					
					this.sendNotification(AppFacade.IMAGE_STARTUP, {imgPanel : imgPanel, mainApplication : mainApplication});
					break;
				case "dataGrid" : 
					var dataGridPanel : Group = new DataGridPanel();
					
					mainApplication.palRight.addElement(dataGridPanel);
					
					this.sendNotification(AppFacade.DATAGRID_STARTUP, {dataGridPanel : dataGridPanel, mainApplication : mainApplication});
					break;
				default : break;
			}
			
		}
		
		public function opening() : void {
			var treeMenu : Tree = data.e.currentTarget as Tree;
			
			
//			var mainApplication : MainApplication = data.mainApplication as MainApplication;
//			
//			var xml:XML=treeMenu.selectedItem as XML;
//			//var text:String=xml.text;
//			//trace(xml.@id);
//			
//			mainApplication.palRight.removeAllElements();
//			
//			var id : String = xml.@id;
//			
			treeMenu.expandItem(treeMenu.selectedItem, false);
			
			//trace(data.e.item);
		}
		
	}
}